<%@page import="java.sql.Statement"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="com.liangjie.bbs.DB"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("utf-8");
	int pId = Integer.parseInt(request.getParameter("pId"));
	int rootId = Integer.parseInt(request.getParameter("rootId"));
	String title = request.getParameter("title");
	String cont = request.getParameter("cont");
	/*
	out.println(pId);
	out.println(rootId);
	out.println(title);
	out.println(cont);
	 */
	Connection conn = DB.getConn();
	boolean autoCommit = conn.getAutoCommit();
	conn.setAutoCommit(false);

	String sql = "insert into article values (null , ?, ?, ? ,? , now(), ?)";
	PreparedStatement pStmt = DB.getPreStmt(conn, sql);
	pStmt.setInt(1, pId);
	pStmt.setInt(2, rootId);
	pStmt.setString(3, title);
	pStmt.setString(4, cont);
	pStmt.setInt(5, 0);
	pStmt.executeUpdate();

	//回复成功，父贴设为非叶子结点
	Statement stmt = DB.getStmt(conn);
	stmt.executeUpdate("update article set isleaf = 1 where id = "
			+ pId);

	conn.commit();
	conn.setAutoCommit(autoCommit);

	DB.close(pStmt);
	DB.close(stmt);
	DB.close(conn);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>回复结果</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>

<body>
	<h1 align="center">恭喜，回复成功！</h1>
	<br>
	<span id="time">6</span>秒后自动跳转到主题列表，如果没有跳转请点击这里：
	<br />
	<a href="./article.jsp">回到主题列表</a>

	<!-- 自动回到主题列表 -->
	<script language="JavaScript1.2" type="text/javascript">
		function delayURL(url, time) {
			var delay = document.getElementById("time").innerHTML;
			if (delay > 1) {
				delay--;
				document.getElementById("time").innerHTML = delay;
			} else {
				window.top.location.href = url;
			}
			setTimeout("delayURL('" + url + "')", 1000);
		}

		delayURL("article.jsp");
	</script>
	<!-- 自动回到主题列表 -->
</body>
</html>
